home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
081-090
/
amok82
/
env2.0
/
env.mod
< prev
next >
Wrap
Text File
|
1993-11-04
|
7KB
|
221 lines
(***************************************************************************
:Program. Env.mod
:Contents. Shows contents of local and global dos environment variables
:Author. Hartmut Goebel [hG] & Thomas Wagner [tom]
:Address. [hG] Aufseßplatz 5, D-8500 Nürnberg 40
:Copyright. Public Domain
:Language. Oberon
:Translator. AmigaOberon V2.43
:History. V1.0, 28 Oct 1991 [hG]
:History. V1.1, 24 Feb 1992 [hG] ^Output: contents now always at col 21
:History. V1.2, 05 Mar 1992 [hG] +template, LocalVars, Flags
:History. V1.3, 12 Apr 1992 [hG] ^flags now always with 4 digits +len
·changed template +version string
:History. V2.0, 02 Sep 1992 [tom] +dir, all, showsys
^using ExAll instead of Examine/ExNext
^many small changes
-bug: memory loss
:Date. 13 Sep 1992 12:02:47
:Remark. needs AmigaDos 2.0
:Usage. env dir,lo=locals/S,go=globals/S,flags/S,len/S,all/S,showsys/S
***************************************************************************)
MODULE Env;
IMPORT
d := Dos,
e := Exec,
ol := OberonLib,
str:= Strings,
s := SYSTEM,
wb := Workbench;
CONST
need20 = "I need at least AmigaDos 2.0\n";
Version = "$VER: env 2.0 (08.09.1992) [hG][tom]";
Template = "DIR,LO=LOCALS/S,GO=GLOBALS/S,FLAGS/S,LEN/S,ALL/S,SHOWSYS/S";
iffFile = "\e[1mIFF\e[m";
infoFile = "\e[1mICON\e[m";
TYPE
EnvVarPtr = UNTRACED POINTER TO EnvVar;
EnvVar = RECORD
name: ARRAY 30 OF CHAR;
contents: e.STRING;
END;
ARGV = STRUCT
dir: e.STRPTR;
locals: LONGINT;
globals: LONGINT;
flags: LONGINT;
len: LONGINT;
all: LONGINT;
showSys: LONGINT;
END;
VAR
Env: EnvVar(*Ptr*);
Var: d.LocalVarPtr;
Me: d.ProcessPtr;
Arguments: d.RDArgsPtr;
Argv: ARGV;
dir: e.STRING;
break : BOOLEAN;
prgname: ARRAY 30 OF CHAR;
DirLen: INTEGER;
(* The following PROCEDURE is called recursively for each entered directory *)
PROCEDURE Examine(dir: ARRAY OF CHAR; file: e.STRPTR);
VAR
Lock: d.FileLockPtr;
more : BOOLEAN;
buffer: ARRAY 128 OF CHAR;
eac: d.ExAllControlPtr;
EAData : POINTER TO ARRAY 512 OF e.BYTE;
ead : d.ExAllDataPtr;
BEGIN
IF ~((d.CheckSignal(LONGSET{d.ctrlC})=LONGSET{}) & ~break) THEN
(* Oh, user want to stop this nice tool? Then stop it (snif) *)
break := TRUE;
ELSE
(* Allocate a buffer for the directory *)
NEW(EAData);
(* Allocate a ExAllControl-sctructure *)
eac := d.AllocDosObject(d.exAllControl,NIL);
IF eac = NIL THEN
HALT(20) END;
eac.lastKey := 0; (* This MUST be set to zero before starting ExAll *)
(* Join dir and file (here a dir, too) *)
IF (file # NIL) THEN
IF ~d.AddPart(dir,file^,LEN(dir)-1) THEN
HALT(20)
END;
END;
IF DirLen = 0 THEN
DirLen := SHORT(str.Length(dir));
IF dir[DirLen] # ":" THEN INC(DirLen); END;
END;
(* Get a lock on this dir *)
Lock := d.Lock(dir,d.sharedLock);
IF Lock = NIL THEN
HALT(20); END;
REPEAT
more := d.ExAll(Lock,EAData^,SIZE(EAData^),d.type,eac);
IF (~more) & (d.IoErr() # d.noMoreEntries) THEN
(* There are no more entries, but DOS didn't stop with
d.noMoreEntries --> ERROR *)
HALT(20) END;
IF eac.entries # 0 THEN
ead := s.VAL(d.ExAllDataPtr,EAData);
REPEAT
IF (ead.type < 0) THEN (* not a directory *)
COPY(dir,buffer);
IF ~d.AddPart(buffer,ead.name^,SIZE(buffer)-1) THEN
HALT(20) END;
IF d.GetVar(buffer,Env.contents,
SIZE(e.STRING),LONGSET{d.globalOnly}) > 0 THEN
IF Env.contents = "FORM" THEN Env.contents := iffFile END;
(* $OvflChk- *)
IF ORD(Env.contents[0])*256 + ORD(Env.contents[1]) = wb.diskMagic THEN
(* $OvflChk= *)
(* so it must be an ICON *)
Env.contents := infoFile; END;
IF str.Length(buffer)>34 THEN buffer[33] := "»" END;
d.PrintF("%-30.30s %s\n",s.ADR(buffer[DirLen]),s.ADR(Env.contents));
END;
ELSE (* directory *)
COPY(ead.name^,buffer);
str.Upper(buffer);
IF (Argv.all # d.DOSFALSE) & (buffer # "SYS")
OR (Argv.showSys # d.DOSFALSE) & (buffer = "SYS") THEN
Examine(dir,ead.name); (* recursively enter dir *)
ELSE
d.PrintF("%s/\n",ead.name); (* only print it's name *)
END;
END;
ead := ead.next; (* get next entry *)
UNTIL ead = NIL;
END;
UNTIL (~more);
d.UnLock(Lock);
d.FreeDosObject(d.exAllControl,eac);
(* $IFNOT GarbageCollector *)
DISPOSE(EAData);
(* $END *)
END;
END Examine;
BEGIN
IF ol.wbStarted THEN HALT(20); END; (* WB, what's THAT? :-) *)
IF d.dos.lib.version < 36 THEN
IF d.Write(d.Output(),need20,SIZE(need20)) = 0 THEN END;
HALT(20);
END;
Me := s.ADR(Version); (* !!dummy!! *)
Me := s.VAL(d.ProcessPtr,ol.Me);
IF ~ d.GetProgramName(prgname,30) THEN prgname := "env" END;
Arguments := d.ReadArgs(Template,Argv,NIL);
IF Arguments = NIL THEN
IF d.PrintFault(d.IoErr(),prgname) THEN END;
HALT(20);
END;
(* No type and dir specified -> show both *)
IF (Argv.locals = d.DOSFALSE)
& (Argv.globals = d.DOSFALSE)
& (Argv.dir = NIL) THEN
Argv.globals := d.DOSTRUE;
Argv.locals := d.DOSTRUE;
END;
IF Argv.dir # NIL THEN Argv.globals := d.DOSTRUE END;
(* local vars *)
IF Argv.locals # d.DOSFALSE THEN
Var := s.VAL(d.LocalVarPtr,Me.localVars.head);
WHILE Var.node.succ # NIL DO
IF Var.node.type = 0 THEN
IF Argv.len # d.DOSFALSE THEN
d.PrintF("%3.3ld ",Var.len);
END;
IF Argv.flags # d.DOSFALSE THEN
d.PrintF("%04.4lx ",s.VAL(INTEGER,Var.flags));
END;
d.PrintF("%-20.20s %s\n",Var.node.name,Var.value);
(*IF d.WriteChars(Var.value^,Var.len) = 0 THEN END;
IF d.PutStr("\n") = 0 THEN END;*)
END;
Var := Var.node.succ;
END;
END;
IF (Argv.globals # d.DOSFALSE) & (Argv.locals # d.DOSFALSE) THEN
IF d.PutStr("\n") = 0 THEN END;
END;
IF (Argv.globals # d.DOSFALSE) THEN
dir := "ENV:"; (* space needed for d.AddPart in Examine *)
Examine(dir,Argv.dir);
END;
CLOSE
IF Arguments # NIL THEN d.FreeArgs(Arguments) END;
END Env.